<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category  Zend
 * @package   Zend_DataGrid
 * @subpackage Column
 * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd     New BSD License
 *
 */

/** @see Zend_DataGrid_Column */
require_once 'Zend/DataGrid/Column.php';

/** @see Zend_Form_Element */
require_once 'Zend/Form/Element.php';


/**
 * Zend_DataGrid_Column_EditCommand
 *
 * The Edit Command column contains the Edit command buttons for editing data items in each row (Edit, Update, Cancel)
 * The button captions are specified using {@link setEditText}, {@link setUpdateText}, and {@link setCancelText}
 * The buttons in the column can be set to display as hyperlinks, push or image buttons by setting the ButtonType property.
 *
 * When an edit button is clicked, the datagrid will generate an onEditCommand event. When an update/cancel
 * button is clicked, the datagrid will generate an onUpdateCommand or an onCancelCommand. You can write
 * these event handlers to change the state of specific datagrid item.
 *
 * @category   Zend
 * @package    Zend_DataGrid
 * @subpackage Column
 * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd     New BSD License
 * @version   $Id: EditCommand.php 6137 2008-09-13 17:37:27Z azoungrana $
 */
class Zend_DataGrid_Column_EditCommand extends Zend_DataGrid_Column
{
    /**#@+
     * The type of editing button
     */
    const BUTTON_HYPERLINK = 'hyperlink';
    const BUTTON_PUSH = 'push';
    const BUTTON_IMAGE = 'image';
    /**#@-*/

    /**
     * Default button type
     */
    const DEFAULT_BUTTON_TYPE = 'hyperlink';

    /**
     * Default button label
     */
    const DEFAULT_CANCEL_LABEL = 'Cancel';
    const DEFAULT_EDIT_LABEL = 'Edit';
    const DEFAULT_UPDATE_LABEL = 'Update';
    /**#@-*/

    /**
     * The button type
     *
     * @var string
     */
    protected $_buttonType = null;

    /**
     * The cancel image url
     *
     * @var string
     */
    protected $_canceImageUrl = null;

    /**
     * The cancel text
     *
     * @var string
     */
    protected $_cancelText = null;

    /**
     * The edit image url
     *
     * @var string
     */
    protected $_editImageUrl = null;

    /**
     * The edit text
     *
     * @var string
     */
    protected $_editText = null;

    /**
     * The update image url
     *
     * @var string
     */
    protected $_updateImageUrl = null;

    /**
     * The update text
     *
     * @var string
     */
    protected $_updateText = null;

    /**
     * Sets the type of command button
     *
     * @param string $value
     * @return Zend_DataGrid_Column_EditCommand
     * @throws  Zend_DataGrid_Column_Exception for invalide button type
     */
    public function setButtonType($value)
    {
        $buttonTypes = array(self::BUTTON_HYPERLINK, self::BUTTON_IMAGE, self::BUTTON_PUSH);
        if (in_array($value, $buttonTypes))
            $this->_buttonType = $value;
        else
            throw new Zend_DataGrid_Column_Exception('The button type must take its value in :'. implode(' ,', $buttonTypes));

        return $this;
    }

    /**
     * Gets the type of command button
     *
     * @return string
     */
    public function getButtonType()
    {
        if (null === $this->_buttonType) {
            $this->_buttonType = self::DEFAULT_BUTTON_TYPE;
        }

        return $this->_buttonType;
    }

    /**
     * Sets the URL of the image file for cancel image buttons
     *
     * @param string $value
     * @return Zend_DataGrid_Column_EditCommand
     */
    public function setCancelImageUrl($value)
    {
        $this->_canceImageUrl = (string) $value;
        return $this;
    }

    /**
     * Gets the URL of the image file for cancel image buttons
     *
     * @return string
     */
    public function getCancelImageUrl()
    {
        return $this->_canceImageUrl;
    }

    /**
     * Sets the caption of the cancel button. Defaults to 'Cancel'.
     *
     * @param string $value
     * @return Zend_DataGrid_Column_EditCommand
     */
    public function setCancelText($value)
    {
        $this->_cancelText = (string) $value;
        return $this;
    }

    /**
     * Gets the caption of the cancel button. Defaults to 'Cancel'.
     *
     * @return string
     */
    public function getCancelText()
    {
        if (null === $this->_cancelText) {
            $this->_cancelText = self::DEFAULT_CANCEL_LABEL;
        }
        return $this->_cancelText;
    }

    /**
     * Sets the URL of the image file for edit image buttons
     *
     * @param string $value
     * @return Zend_DataGrid_Column_EditCommand
     */
    public function setEditImageUrl($value)
    {
        $this->_editImageUrl = (string) $value;
        return $this;
    }

    /**
     * Gets the URL of the image file for edit image buttons
     *
     * @return string
     */
    public function getEditImageUrl()
    {
        return $this->_editImageUrl;
    }

    /**
     * Sets the caption of the edit button. Defaults to 'Edit'.
     *
     * @param string $value
     * @return Zend_DataGrid_Column_EditCommand
     */
    public function setEditText($value)
    {
        $this->_editText = (string) $value;
        return $this;
    }

    /**
     * Gets the caption of the edit button. Defaults to 'Edit'.
     *
     * @return string
     */
    public function getEditText()
    {
        if (null === $this->_editText) {
            $this->_editText = self::DEFAULT_EDIT_LABEL;
        }
        return $this->_editText;
    }

    /**
     * Sets the URL of the image file for update image buttons
     *
     * @param string $value
     * @return Zend_DataGrid_Column_EditCommand
     */
    public function setUpdateImageUrl($value)
    {
        $this->_updateImageUrl = (string) $value;
        return $this;
    }

    /**
     * Gets the URL of the image file for update image buttons
     *
     * @return string
     */
    public function getUpdateImageUrl()
    {
        return $this->_updateImageUrl;
    }

    /**
     * Sets the caption of the update button. Defaults to 'Update'.
     *
     * @param string $value
     * @return Zend_DataGrid_Column_EditCommand
     */
    public function setUpdateText($value)
    {
        $this->_updateText = (string) $value;
        return $this;
    }

    /**
     * Gets the caption of the update button. Defaults to 'Update'.
     *
     * @return string
     */
    public function getUpdateText()
    {
        if (null === $this->_updateText) {
            $this->_updateText = self::DEFAULT_UPDATE_LABEL;
        }
        return $this->_updateText;
    }



}
